package com.java1412.entity;

import lombok.Data;
import lombok.ToString;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Property;
import org.neo4j.ogm.annotation.Relationship;
import org.springframework.data.neo4j.core.schema.Id;

import java.util.HashSet;
import java.util.Set;


/**
 * @author java1412
 * @create 2021-07-02 17:34
 */
@Data
@ToString
@NodeEntity("ParentNode")
public class ParentNode {

    @Id
    @GeneratedValue
    private Long id;

    @Property(name = "name")
    private String name;

    @Relationship(type = "RelationEdge")
    private Set<RelationEdge> sets = new HashSet<>();

    public ParentNode(String name) {
        this.name = name;
    }

    public void addRelation(SonNode sonNode, String name) {
        RelationEdge relationEdge = new RelationEdge(this, name, sonNode);
        sets.add(relationEdge);
        sonNode.getSets().add(relationEdge);
    }
}
